<template>
  <el-dialog title="新增施工进场" :visible.sync="dialogFormVisible" @close="close" :destroy-on-close="true" width="80%">
    <el-form ref="form" :model="form" label-width="120px" :rules="rules">
      <el-row>
        <el-col :span="8">
          <el-form-item prop="name" label="标段">
            <el-select size="medium" v-model="form.bd_id" placeholder="选择标段">
              <el-option
                :label="item.bdmc"
                :value="item.id.toString()"
                v-for="item in BdData"
                :key="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item prop="jcrq" label="进场日期">
            <el-date-picker
              value-format="yyyy-MM-dd"
              size="medium"
              v-model="form.jcrq"
              type="date"
              placeholder="选择日期"
            ></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row type="flex" justify="start"></el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button size="medium" @click="dialogFormVisible=false">取 消</el-button>
      <el-button
        size="medium"
        type="primary"
        @click="save"
        v-if="$route.query.is_sealed == 1"
        :loading="loading"
      >保 存</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  props: ["dialogFormVisible1", "item", "BdData"],
  data() {
    return {
      form: {},
      rules: {
        bd_id: [{ required: true, message: "该值不能为空", trigger: "blur" }],
        jcrq: [{ required: true, message: "该值不能为空", trigger: "blur" }]
      },
      formLabelWidth: "140px",
      dialogFormVisible: false,
      loading: false
    };
  },
  methods: {
    close() {
      this.$refs.form.resetFields();
      this.$emit("close");
    },
    save() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.loading = true;
          this.form.xm_id = this.$route.query.xm_id;
          console.log(this.form);
          this.$post("/api/QqSgjc/actions", this.form).then(res => {
            if (res.code == 200) {
              this.$message({
                message: res.msg,
                type: "success"
              });
              this.dialogFormVisible = false;
            } else {
              this.$message({
                message: res.msg,
                type: "error"
              });
            }
            this.loading = false;
          });
        } else {
          return false;
        }
      });
    }
  },
  watch: {
    dialogFormVisible1(news) {
      this.dialogFormVisible = news;
    },
    dialogFormVisible(news) {
      if (!news) {
        this.close();
      }
    },
    item(news) {
      this.form = { ...news };
    }
  }
};
</script>

<style>
</style>